#include "HudNodeOsg.h"
#include <HudNode.h>
#include <ForegroundSystem.h>
HudNodeOsg::HudNodeOsg(QObject *parent)
{
    osg::ref_ptr<ForegroundSystem> foreSys = new ForegroundSystem;
    m_object = foreSys;
    foreSys->creatDefaultText();
}

HudNodeOsg::~HudNodeOsg()
{

}

double HudNodeOsg::getBackPosX()
{
    double posx = 0.0;
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        posx = foregroundPtr->getPositionX();
    }
    return posx;
}

void HudNodeOsg::setBackPosX(double posValue)
{
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        foregroundPtr->setPositionX(posValue);
    }
}

double HudNodeOsg::getBackPosY()
{
    double posx = 0.0;
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        posx = foregroundPtr->getPositionY();
    }
    return posx;
}

void HudNodeOsg::setBackPosY(double posValue)
{
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        foregroundPtr->setPositionY(posValue);
    }

}

double HudNodeOsg::getBackWidth()
{
    double posx = 0.0;
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        posx = foregroundPtr->getWidth();
    }
    return posx;
}

void HudNodeOsg::setBackWidth(double posValue)
{
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        foregroundPtr->setWidth(posValue);
    }
}

double HudNodeOsg::getBackHeight()
{
    double posx = 0.0;
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        posx = foregroundPtr->getHeight();
    }
    return posx;
}

void HudNodeOsg::setBackHeight(double posValue)
{
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        foregroundPtr->setHeight(posValue);
    }
}

double HudNodeOsg::getBackTransparent()
{
    double posx = 0.0;
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        posx = foregroundPtr->getTransparent();
    }
    return posx;
}

void HudNodeOsg::setBackTransparent(double transparent)
{
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        foregroundPtr->setTransparent(transparent);
    }
}

QVector3D HudNodeOsg::getTextPos()
{
    QVector3D v;
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        osg::Vec3 textPos = foregroundPtr->getDefaultTextPosition();
        v.setX(textPos[0]);
        v.setY(textPos[1]);
        v.setZ(textPos[2]);
    }
    return v;
}

void HudNodeOsg::setTextPos(QVector3D pos)
{
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        osg::Vec3 textPos(pos.x(), pos.y(), pos.z());
        foregroundPtr->setDefaultTextPosition(textPos);
    }
}

QColor HudNodeOsg::getTextColor()
{
    QColor v;
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        osg::Vec4 textColor = foregroundPtr->getDefaultTextColor();
        v.setRedF(textColor[0]);
        v.setGreenF(textColor[1]);
        v.setBlueF(textColor[2]);
        v.setAlphaF(textColor[3]);
    }
    return v;
}

void HudNodeOsg::setTextColor(QColor &color)
{
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        osg::Vec4 textColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
        foregroundPtr->setDefaultTextColor(textColor);
    }
}

double HudNodeOsg::getTextCharacterSize()
{
    double characterSize = 0;
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        characterSize = foregroundPtr->getDefaultTextCharacterSize();
    }
    return characterSize;
}

void HudNodeOsg::setTextCharacterSize(double size)
{
    ForegroundSystem* foregroundPtr = dynamic_cast<ForegroundSystem*>(m_object.get());
    if(foregroundPtr != NULL)
    {
        foregroundPtr->setDefaultTextCharacterSize(size);
    }
}
